home *** CD-ROM | disk | FTP | other *** search
- unit NonFlatButtons;
-
- {$ifdef Ver100} { Delphi 3.0x }
- {$define DelphiLessThan4}
- {$endif}
- {$ifdef Ver110} { C++ Builder 3.0x }
- {$define DelphiLessThan4}
- {$endif}
-
- interface
-
- procedure Register;
-
- implementation
-
- uses
- CommonStuff, ExtCtrls, Buttons, Menus, Forms, Controls,
- SysUtils, Dialogs, ComCtrls;
-
- type
- TNonFlatButtons = class(TObject)
- private
- {$ifdef DelphiLessThan4}
- FSpeedBar: TPanel;
- {$else}
- FSpeedBars: array[1..4] of TToolBar;
- {$endif}
- FSpeedBarPopup: TPopupMenu;
- FSpeedBarFlat: TMenuItem;
- protected
- procedure SetFlatButtons(Value: Boolean);
- procedure DoFlatButtons(Sender: TObject);
- public
- constructor Create;
- destructor Destroy; override;
- procedure Setup;
- procedure TidyUp;
- end;
-
- resourcestring
- SFlat = '&Flat Buttons';
-
- const
- {$ifdef DelphiLessThan4}
- SSpeedBarPopup = 'SpeedbarMenu'; //Speed bar's TPopupMenu
- SSpeedBar = 'SpeedPanel'; //Speed bar component
- {$else}
- SSpeedBarPopup = 'ToolBarsPopup'; //Speed bar's TPopupMenu
- SStandardBar = 'StandardToolBar';
- SViewBar = 'ViewToolBar';
- SCustomBar = 'CustomToolBar';
- SDebugBar = 'DebugToolBar';
- {$endif}
- SRegFlatSpeedBar = 'Flat Speedbar'; //Registry string
-
- constructor TNonFlatButtons.Create;
- begin
- inherited Create;
- end;
-
- destructor TNonFlatButtons.Destroy;
- begin
- TidyUp;
- inherited Destroy
- end;
-
- procedure TNonFlatButtons.Setup;
- begin
- //Make sure there is an options menu - bear in mind
- //that the other options code might not be being used
- Stuff.AddOptionsItem;
- //Find speed bar(s)
- {$ifdef DelphiLessThan4}
- FSpeedBar := GetComponent(Application.MainForm, SSpeedBar, SGenericError + SSpeedBar) as TPanel;
- {$else}
- FSpeedBars[1] := GetComponent(Application.MainForm, SStandardBar, SGenericError + SStandardBar) as TToolBar;
- FSpeedBars[2] := GetComponent(Application.MainForm, SViewBar, SGenericError + SViewBar) as TToolBar;
- FSpeedBars[3] := GetComponent(Application.MainForm, SCustomBar, SGenericError + SCustomBar) as TToolBar;
- FSpeedBars[4] := GetComponent(Application.MainForm, SDebugBar, SGenericError + SDebugBar) as TToolBar;
- {$endif}
- //Find speed bar's popup menu
- FSpeedBarPopup := GetComponent(Application.MainForm, SSpeedBarPopup, SGenericError + SSpeedBarPopup) as TPopupMenu;
- //Set up option menu item
- FSpeedBarFlat := NewItem(SFlat, 0,
- Stuff.Ini.ReadBool(SRegSection, SRegFlatSpeedBar,
- {$ifdef DelphiLessThan4}
- (FSpeedBar.Controls[0] as TSpeedButton).Flat),
- {$else}
- FSpeedBars[1].Flat),
- {$endif}
- True, DoFlatButtons, 0, '');
- {$ifdef DelphiLessThan4}
- FSpeedBarPopup.Items.Insert(1, FSpeedBarFlat);
- {$else}
- Stuff.FOptions.Add(FSpeedBarFlat);
- {$endif}
- //Set the speedbar properties as dictated by registry
- SetFlatButtons(FSpeedBarFlat.Checked);
- end;
-
- procedure TNonFlatButtons.TidyUp;
- begin
- //Get rid of option menu item
- FSpeedBarFlat.Free;
- //Restore IDE original state
- SetFlatButtons(True);
- //Save option information
- Stuff.Ini.WriteBool(SRegSection, SRegFlatSpeedBar, FSpeedBarFlat.Checked);
- end;
-
- procedure TNonFlatButtons.SetFlatButtons(Value: Boolean);
- var
- Loop: Integer;
- begin
- //Set Flat option as appropriate
- {$ifndef DelphiLessThan4}
- for Loop:= Low(FSpeedBars) to High(FSpeedBars) do
- FSpeedBars[Loop].Flat := Value
- {$else}
- with FSpeedBar do
- for Loop := 0 to ControlCount - 1 do
- if Controls[Loop] is TSpeedButton then
- TSpeedButton(Controls[Loop]).Flat := Value
- {$endif}
- end;
-
- procedure TNonFlatButtons.DoFlatButtons(Sender: TObject);
- begin
- //Toggle Flat option
- with (Sender as TMenuItem) do
- begin
- Checked := not Checked;
- SetFlatButtons(Checked)
- end
- end;
-
- var
- NonFlatButtonsObject: TNonFlatButtons;
-
- procedure Register;
- begin
- NonFlatButtonsObject.Setup
- end;
-
- initialization
- try
- NonFlatButtonsObject := TNonFlatButtons.Create
- except
- on E: Exception do
- ShowMessage(SSetupError + ': ' + E.Message)
- end
- finalization
- NonFlatButtonsObject.Free
- end.
-